export const isPromise=obj=>!!obj&&(typeof obj==='object'||typeof obj==='function')&&typeof obj.then==='function';
let click=0,clickDate=null,Idex
export const toDoubleClick=(callback,Index)=>{
  if(Index===Idex||Idex===undefined){
    click+=1 
    if(clickDate!==null&&click>1&&new Date().getTime()-clickDate.getTime()<500){
      callback();click=0;clickDate=null
   }
    clickDate=new Date()
 }else{click=1;clickDate=new Date()}
  Idex=Index
}
function easeInOutQuad(t:number,s:number,c:number,d:number){t/=d/2;if(t<1){return c/2*t*t+s}t--;return-c/2*(t*(t-2)-1)+s;};
export function scrollTo(to:number,d:number=500,cb:Function){
  const s=document.documentElement.scrollTop||document.body.parentNode.scrollTop||document.body.scrollTop;
  const c=to-s,increment=20;let t=0;var animateScroll=function(){t+=increment;
    var val=easeInOutQuad(t,s,c,d);
    document.documentElement.scrollTop=document.body.parentNode.scrollTop=document.body.scrollTop=val;
    if(t<d){window.setTimeout(animateScroll,50/3)}else{if(cb&&typeof(cb)==='function'){cb()}}
 };animateScroll()
}
var hasOwn={}.hasOwnProperty;
export const domPercent=()=>Math.floor(window.parent.innerWidth/350);
export const classNames=(...a)=>{var classes=[];
  for(var i=0; i<a.length; i++){
    var arg=a[i];if(!arg) continue;
    var argType=typeof arg;
    if(argType==='string'|| argType==='number'){
      classes.push(arg);
   }else if(Array.isArray(arg)){
      if(arg.length){
        var inner=classNames.apply(null, arg);
        if(inner) classes.push(inner);
     }
   }else if(argType==='object')
      if(arg.toString !==Object.prototype.toString)
        classes.push(arg.toString());
      else for(var key in arg)
        if(hasOwn.call(arg, key)&&arg[key])
          classes.push(key);
 }var str=classes.join('');classes=arg=null;
  return str;
}
